package com.ace.lab.starter.config;

import com.ace.lab.starter.annotation.RpcClientScan;
import com.ace.lab.starter.resolver.ZookeeperNameResolverProvider;
import com.ace.lab.starter.utils.ApplicationContextHelper;
import com.ace.lab.starter.utils.BeanFactoryHelper;
import io.grpc.NameResolverProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({ConsumerProperties.class, ZookeeperProperties.class})
@RpcClientScan({"com.ace.lab"})
public class ServiceConsumerConfiguration {

    @Bean
    public ApplicationContextHelper applicationContextHelper() {
        return new ApplicationContextHelper();
    }

    @Bean
    public static BeanFactoryHelper beanFactoryHelper() {
        return new BeanFactoryHelper();
    }

    @Bean
    @ConditionalOnMissingBean
    public NameResolverProvider zookeeperNameResolverFactory() {
        return new ZookeeperNameResolverProvider();
    }

}
